<?php
namespace Home\Controller;
use Think\Controller;
class SetController extends CommonController {
    public function index(){
    	$this->assign('title',"用户中心");
        $this->display();
    }

    public function set()
    {
    	$this->assign('title',"基本设置");
    	$this->display();
    }

    public function upload()
    {
    	$upload = new \Think\Upload();// 实例化上传类
	    $upload->maxSize   =     3145728 ;// 设置附件上传大小
	    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
	    $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
	    $upload->savePath  =     ''; // 设置附件上传（子）目录
	    // 上传文件 
	    $info   =   $upload->upload();

	    if(!$info) {// 上传错误提示错误信息
	        echo $upload->getError();
	    }else{// 上传成功
	    	$info = current($info);

	    	$path = "Uploads/".$info['savepath'].'/'.$info['savename'];

	    	$_SESSION['face'] = $path;

	    	$sql ="update user set face='{$path}' where id='{$_SESSION['id']}'";

	    	$res = M()->execute($sql);

	    	if($res){
	    		echo $path;
	    	}else{
				echo "0";
	    	}
	    }
    }
}